;;

(require 'font-lock)
(eval-when-compile
  (require 'regexp-opt))

(defvar house5-mode-hook nil)
;;(add-to-list 'auto-mode-alist '("\\.pig\\'" . house5-mode))

(defvar house5-indent-level 2
  "Defines 2 spaces for indentation")

;; syntax coloring
(defvar house5-font-lock-keywords
 '(
   ("\\(#\\|\-\-\\).*$" . font-lock-comment-face)
  ("\\<\\(LOAD\\|FILTER\\|FOREACH\\|GENERATE\\|AND\\|OR\\|ANY\\|ALL\\|ARRANGE\\|AS\\|ASC\\|BY\\|cache\\|cat\\|cd\|COGROUP\\|copyFromLocal\\|copyToLocal\\|cp\\|cross\\|define\\|desc\\|describe\\|diff\\|distinct\\|du\\|dump\\|eval\\|exec\\|explain\\|flatten\\|generate\\|group\\|help\\|if\\|illustrate\\|inner\\|input\\|into\\|is\\|join\\|kill\\|limit\\|ls\\|mkdir\\|mv\\|not\\|null\\|or\\|order\\|outer\\|output\\|parallel\\|pig\\|pwd\\|quit\\|register\\|rm\\|rmf\\|run\\|sample\\|set\\|ship\\|size\\|split\\|stderr\\|stdin\\|stdout\\|store\\|stream\\|through\\|union\\|using\\)\\>" . font-lock-keyword-face)
   ("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face))  ;; functions
   ("\\<\\(\\w+\\)\\>\\s-*=" (1 font-lock-variable-name-face))
   ("'.+'" . font-lock-string-face)
   ("\\<\\(bytearray\\|chararray\\|double\\|int\\|float\\|long\\|tuple\\|bag\\|map\\)\\>" . font-lock-type-face)
   )
  "House5 Keywords")

;; C/C++ comments; also allowing underscore in words
(defvar house5-mode-syntax-table
  (let ((house5-mode-syntax-table (make-syntax-table)))
    (modify-syntax-entry ?_ "w" house5-mode-syntax-table)
    (modify-syntax-entry ?/ ". 1456" house5-mode-syntax-table)
    (modify-syntax-entry ?* ". 23" house5-mode-syntax-table)
    (modify-syntax-entry ?\n "> b" house5-mode-syntax-table)
    house5-mode-syntax-table)
  "Syntax table for house5-mode")

(defun house5-turn-on ()
  "Mode for editing House5 files"
  (message "turn on house5")
  (font-lock-add-keywords nil
                          house5-font-lock-keywords)
 ;; (kill-all-local-variables)
 ;; (set-syntax-table house5-mode-syntax-table)
;;  (set (make-local-variable 'font-lock-defaults) '(house5-font-lock-keywords nil t))
  ;(setq major-mode 'house5-mode)
;;  (setq minor-mode 'house5-mode)

  ;;(run-hooks 'house5-mode-hook)
;;  (set (make-local-variable 'indent-line-function) 'house5-indent-line)
  )

(defun house5-turn-off ()
  "Turn off house5-mode."
  (message "turn off"))


(define-minor-mode house5-mode
  "house5 templates by qwy"
  :lighter " house5"
  (progn
    (if house5-mode
        (house5-turn-on)
      (house5-turn-off))))


(provide 'house5-mode)
